package be.ac.ua.ecampus.uacmat;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class SynchServlet
 */
@WebServlet("/synchronize")
public class SynchServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public SynchServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.getRequestDispatcher("/synchronize.jsp").forward(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		QueryHandler handler = new QueryHandler();
		handler.connectOldDB();
		handler.synchTrainings();
		handler.synchCourses();
		handler.synchSyllabus();
		handler.synchPrograms();
		handler.synchPackets();
		handler.synchPacketSyllabus();
		handler.synchCourseProgram();
		handler.synchCourseSyllabus();
		
		request.setAttribute("synchronization", true);
		request.getRequestDispatcher("/synchronize.jsp").forward(request, response);
	}

}
